package com.lyrcsoft;

import com.lyrcsoft.services.MyInterface;
import com.lyrcsoft.services.impl.MyService;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;

import java.lang.reflect.Method;

/**
 * @author fujc2dev@126.com
 * @date 2024-01-18 13:24
 */
public class CglibProxyFactorySupport {

	public static void main(String[] args) {
		MyService target = new MyService();
		ProxyFactory proxyFactory  =new ProxyFactory();
		proxyFactory.setTarget(target);
		proxyFactory.addAdvice(new MethodBeforeAdvice() {
			@Override
			public void before(Method method, Object[] args, Object target) throws Throwable {
				System.out.println("xxx");
			}
		});
		MyService myService = (MyService) proxyFactory.getProxy();
		myService.test();
		MyInterface myInterface = (MyInterface) proxyFactory.getProxy();
		myInterface.test();
	}
}
